package com.bestom.hardwaretest.File;

import com.bestom.hardwaretest.util.SharedPreferencesUtil;

import java.io.File;
import java.io.IOException;

public class FilesManager extends FilesHelper{

	private static final String TAG = "FilesManager";

	private File relayFile,_485File,radarFile,redLedFile,buzzerFile,dutyCycleFile;

	public FilesManager() {
		relayFile = new File((String) SharedPreferencesUtil.getInstance().getValue(FilesConstant.mRelayPref,FilesConstant.mRelayDefaultPath));
		radarFile = new File((String) SharedPreferencesUtil.getInstance().getValue(FilesConstant.mRadarPref,FilesConstant.mRadarDefaultPath));
		redLedFile = new File((String) SharedPreferencesUtil.getInstance().getValue(FilesConstant.mIrPref,FilesConstant.mIrDefaultPath));
		buzzerFile = new File((String) SharedPreferencesUtil.getInstance().getValue(FilesConstant.mBuzzerPref,FilesConstant.mBuzzerDefaultPath));
		dutyCycleFile = new File((String) SharedPreferencesUtil.getInstance().getValue(FilesConstant.mLedPref,FilesConstant.mLedDefaultPath));
	}
	public FilesManager(String only485){
		_485File = new File((String) SharedPreferencesUtil.getInstance().getValue(FilesConstant.m485Pref,FilesConstant.m485DefaultPath));
	}

	public boolean writeRadar(String value){
		try {
			return write(radarFile, value);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}
	public boolean writeRedLed(String value){
		try {
			return write(redLedFile, value);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}

	public boolean writeBuzzer(String value){
		try {
			return write(buzzerFile, value);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}

	public boolean writeLed(String value){
		try {
			return write(dutyCycleFile, value);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}

	public boolean write485(String value){
		try {
			return write(_485File, value);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}

	public boolean writeRelay(String value){
		try {
			return write(relayFile, value);
		} catch (IOException e) {
			e.printStackTrace();
			return  false;
		}
	}

	public String readRadar(){
		return read(radarFile);
	}

}
